package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.DeviceObjectRelateLogDao;
import cn.topevery.garden.entity.po.DeviceObjectRelate;
import cn.topevery.garden.entity.po.DeviceObjectRelateLog;
import cn.topevery.garden.entity.query.DeviceObjectRelateLogQuery;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 *
 * @author code-generate
 * @date 2021-09-08
 */
@Service
public class DeviceObjectRelateLogLogic extends BaseLogic<DeviceObjectRelateLog> {
    @Autowired
    DeviceObjectRelateLogDao deviceObjectRelateLogDao;

    @Override
    public BaseEntityDao<DeviceObjectRelateLog, Integer> getDao() {
        return deviceObjectRelateLogDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<DeviceObjectRelateLog> listPage(DeviceObjectRelateLogQuery query) {
        return deviceObjectRelateLogDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        deviceObjectRelateLogDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param userId             the user id
     * @param deviceObjectRelate 实体
     * @param type 操作类型(1:新增、2:匹配、3:回收、4:退出运营、5:解除绑定、6:分配标段、7:编辑)
     * @author wenzhao.lin
     * @created 2021 -09-08 17:33:27 Save or update.
     */
    public void saveOrUpdate(String userId, DeviceObjectRelate deviceObjectRelate, Integer type){
        DeviceObjectRelateLog deviceObjectRelateLog = new DeviceObjectRelateLog();
        deviceObjectRelateLog.setCode(deviceObjectRelate.getCode());
        deviceObjectRelateLog.setDeviceId(deviceObjectRelate.getDeviceId());
        deviceObjectRelateLog.setObjectId(deviceObjectRelate.getObjectId());
        deviceObjectRelateLog.setObjectType(deviceObjectRelate.getObjectType());
        deviceObjectRelateLog.setOptType(type);

        deviceObjectRelateLogDao.saveOrUpdate(userId,deviceObjectRelateLog);
    }
}
